﻿@model OnlineCustomerSearchModel

@{
    //page title
    ViewBag.PageTitle = T("Admin.Customers.OnlineCustomers").Text;
    //active menu item (system name)
    NopHtml.SetActiveMenuItemSystemName("Online customers");
}

@{
    const string hideSearchBlockAttributeName = "OnlineCustomersListPage.HideSearchBlock";
    var hideSearchBlock = await genericAttributeService.GetAttributeAsync<bool>(await workContext.GetCurrentCustomerAsync(), hideSearchBlockAttributeName);
}

<div class="content-header clearfix">
    <h1 class="float-left">
        @T("Admin.Customers.OnlineCustomers")
    </h1>
    <div class="float-right">
        &nbsp;
        @await Component.InvokeAsync(typeof(AdminWidgetViewComponent), new { widgetZone = AdminWidgetZones.OnlineCustomerListButtons, additionalData = Model })
    </div>
</div>

<section class="content">
    <div class="container-fluid">
    <div class="form-horizontal">
        <div class="cards-group">
                <div class="card card-default card-search">
                    <div class="card-body">
                        <div class="row search-row @(!hideSearchBlock ? "opened" : "")" data-hideAttribute="@hideSearchBlockAttributeName">
                            <div class="search-text">@T("Admin.Common.Search")</div>
                            <div class="icon-search"><i class="fas fa-magnifying-glass" aria-hidden="true"></i></div>
                            <div class="icon-collapse"><i class="far fa-angle-@(!hideSearchBlock ? "up" : "down")" aria-hidden="true"></i></div>
                        </div>
                        <div class="search-body @(hideSearchBlock ? "closed" : "")">
                            <div class="row">
                                <div class="col-md-5">
                                    <div class="form-group row">
                                        <div class="col-md-4">
                                            <nop-label asp-for="SelectedCustomerRoleIds" />
                                        </div>
                                        <div class="col-md-8">
                                            <nop-select asp-for="SelectedCustomerRoleIds" asp-items="Model.AvailableCustomerRoles" asp-multiple="true" />
                                            <script>
                                                $(function() {
                                                    var rolesIdsInput =
                                                        $('#@Html.IdFor(model => model.SelectedCustomerRoleIds)').select2({
                                                            closeOnSelect: false,
                                                @if (!Model.AvailableCustomerRoles.Any())
                                                {
                                                    <text>
                                                                disabled: true,
                                                                placeholder: '@T("Admin.Configuration.ACL.NoCustomerRolesAvailable")',
                                                    </text>
                                                }
                                                        });
                                                });
                                            </script>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="text-center col-12">
                                    <button type="button" id="search-customers" class="btn btn-primary btn-search">
                                        <i class="fas fa-magnifying-glass"></i>
                                        @T("Admin.Common.Search")
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            <div class="card card-default">
                <div class="card-body">
                    <nop-doc-reference asp-string-resource="@T("Admin.Documentation.Reference.OnlineCustomers", Docs.OnlineCustomers + Utm.OnAdmin)"/>

                    @await Html.PartialAsync("Table", new DataTablesModel
                    {
                        Name = "onlinecustomers-grid",
                        UrlRead = new DataUrl("List", "OnlineCustomer", null),
                        Length = Model.PageSize,
                        LengthMenu = Model.AvailablePageSizes,
                        SearchButtonId = "search-customers",
                        Filters = new List<FilterParameter>
                        {
                            new FilterParameter(nameof(Model.SelectedCustomerRoleIds)),
                        },
                        ColumnCollection = new List<ColumnProperty>
                        {
                            new ColumnProperty(nameof(OnlineCustomerModel.CustomerInfo))
                            {
                                Title = T("Admin.Customers.OnlineCustomers.Fields.CustomerInfo").Text,
                                Width = "100",
                                Render = new RenderLink(new DataUrl("~/Admin/Customer/Edit", nameof(CustomerModel.Id)))
                            },
                            new ColumnProperty(nameof(OnlineCustomerModel.LastIpAddress))
                            {
                                Title = T("Admin.Customers.OnlineCustomers.Fields.IPAddress").Text,
                                Width = "100"
                            },
                            new ColumnProperty(nameof(OnlineCustomerModel.Location))
                            {
                                Title = T("Admin.Customers.OnlineCustomers.Fields.Location").Text,
                                Width = "100"
                            },
                            new ColumnProperty(nameof(OnlineCustomerModel.LastActivityDate))
                            {
                                Title = T("Admin.Customers.OnlineCustomers.Fields.LastActivityDate").Text,
                                Width = "200",
                                Render = new RenderDate()
                            },
                            new ColumnProperty(nameof(OnlineCustomerModel.LastVisitedPage))
                            {
                                Title = T("Admin.Customers.OnlineCustomers.Fields.LastVisitedPage").Text,
                                Width = "100"
                            }
                        }
                    })
                </div>
            </div>
        </div>
    </div>
</div>
</section>